IInteraction interface¶
Defined in
Namespace: ReactiveUI.Reactive
Assembly: ReactiveUI.Reactive.dll
Full name: ReactiveUI.Reactive.IInteraction<T1, T2>
Modifiers: public abstract
Summary¶
Represents an interaction between collaborating application components.
Applies to
net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471
Remarks¶
Interactions allow collaborating components in an application to ask each other questions. Typically, interactions allow a view model to get the user's confirmation from the view before proceeding with some operation. The view provides the interaction's confirmation interface in a handler registered for the interaction.
Interactions have both an input and an output. Interaction inputs and outputs use generic type parameters. The interaction's input provides handlers the information they require to ask a question. The handler then provides the interaction with an output as the answer to the question.
Examples¶
<![CDATA[
public class ExportViewModel : ReactiveObject
{
public Interaction<ExportRequest, bool> ConfirmExport { get; } = new();
public Task<bool> TryExportAsync(ExportRequest request) => ConfirmExport.Handle(request).ToTask();
}
public partial class ExportView : ReactiveUserControl<ExportViewModel>
{
public ExportView()
{
this.WhenActivated(disposables =>
ViewModel!.ConfirmExport.RegisterHandler(async context =>
{
var decision = await dialogService.ShowAsync(context.Input);
context.SetOutput(decision);
}).DisposeWith(disposables));
}
}
]]>
Methods¶
| Name | Summary |
|---|---|
| RegisterHandler | Registers a synchronous interaction handler. |
| Handle | Handles an interaction and asynchronously returns the result. |